<?	
header('Access-Control-Allow-Origin: *');

require_once("model/lang_vn.php");
require_once("model/config.php");
require "model/sql.class.php";
require "view/pub.class.php";

$sql=new sql();
$pub=new pub();
$sql->CONNECT_DB(HOST,USER,PASS,DB);
$mv_ID	= $_REQUEST['Catch_Id'];
$mv_hdd = $_REQUEST['mv_hdd'];		
$sesHd308 = $_REQUEST['hd308'];
if(($mv_ID>0)&&($mv_hdd>0)){				
	$m_result1 = mysql_query("DELETE FROM movie_tpm WHERE mv_ID='0'");
	$result = mysql_query("SELECT * FROM movie_tpm WHERE mv_ID='".$mv_ID."' AND tpm_session='".$sesHd308."'");
	if(mysql_num_rows($result)<=0){				
			$m_result = mysql_query("INSERT INTO movie_tpm(tpm_session,mv_ID,mv_hdd,tpm_date) VALUES('".$sesHd308."','".$mv_ID."','".$mv_hdd."','".date('Y/m/d')."')");		
	}else{
			$m_result2 = mysql_query("DELETE FROM movie_tpm WHERE mv_ID='".$mv_ID."'  AND tpm_session='".$sesHd308."'");
	}
}
$results = mysql_query("SELECT SUM(mv_hdd) as tong FROM movie_tpm WHERE tpm_session='".$sesHd308."' AND mv_ID>0 GROUP BY mv_ID,tpm_session");

$mhdd = 0;
while ($k=mysql_fetch_array($results)) {		
	$mhdd = $mhdd + $k['tong'];
}
$percen = $mhdd/2000*100;
$result2 = mysql_query("SELECT COUNT(mv_hdd) as soluong FROM movie_tpm WHERE tpm_session='".$sesHd308."' AND mv_ID>0 GROUP BY mv_ID,tpm_session");
$soluong = mysql_num_rows($result2)	;
$str_mhdd = "";
if($mhdd>1000){
	$t = intval($mhdd/1000) . "T ";
	$g = $mhdd % 1000;	
	if($g>0){
		$str_mhdd = $t . $g . " GB";	
	}else{
		$str_mhdd = $t;
	}	
} 
else{
	$str_mhdd = $mhdd . " GB";
}
?>
<form name="form1" method="post" action="page.php" id="form1">   
	<div class='shopping'>
		<div style='background:gray;'>
			<span style='color:red;font-size:15'>Hot line:</span>
			<span style='color:blue;font-size:15'>0166.4.072.179</span>
		</div>
		<div class='filmNum'><span id="num"><?=$soluong?></span></div>
		<div class='filmSize'><span id="cap"><?=$str_mhdd?></span></div>
		<div>
			<a href="<?=WEBSITE?>/?cc=cart_movie">Hoàn tất</a> &nbsp;| &nbsp;
			<a href="<?=WEBSITE?>/?cc=movie&carttype=huy">Hủy</a> &nbsp;|&nbsp;
			<a href="<?=WEBSITE?>/?cc=movie&carttype=xemlai">Xem lại</a>
<!-- 			<img src="image/btn_fin.jpg" border="0" > -->
		</div>	
		<div>
	</div>
</form>
<script type="application/javascript">
	$('.shopping').css('left',getPositionX());
</script>
